<?php
	class region{
		public function addRegion($rname,$rlevel){
			$t=new db_table(NULL,"zyw_scenic_region");
			$t->insert();
			$t->rname=$rname;
			$t->rlevel=$rlevel;
			$t->ref=0;
			$t->post();
		}
		public function getRegionList(){
			$t=new db_recordset(NULL,"zyw_scenic_region");
			$sql="select * from zyw_scenic_region order by rlevel";
			$t->query($sql,-1);
			$reglist=$t->getRecords();
			return $reglist;
		}
		public function delRegion($rid){
			$t=new db_table(NULL,"zyw_scenic_region");
			$t->locate($rid,-1);
			if($t->record_count()!=1) return false;
			if($t->ref>0)	return false;
			$t0=new db_recordset(NULL,"zyw_scenic_region");
			$sql="delete from zyw_scenic_region where rid='$rid'";
			$t0->exec($sql,-1);
			return true;
		}
		public function getRegionByid($rid){
			$t=new db_recordset(NULL,"zyw_scenic_region");
			$sql="select * from zyw_scenic_region where rid='$rid'";
			$t->query($sql,-1);
			$regionArr=$t->getRecords();
			return $regionArr[0];
		}
		public function updateRegion($rid,$rname,$rlevel){
			$t=new db_table(NULL,"zyw_scenic_region");
			$t->locate($rid,-1);
			if($t->record_count()!=1) return false;
			$t->rname=$rname;
			$t->rlevel=$rlevel;
			$t->post();
			return true;
		}
	}
?>